<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>角色菜单动作配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <#include "../../include/layui.ftl" />
    <style>
        .layui-card{
            margin-bottom: 0px;
        }
        .layui-form-checkbox[lay-skin=primary] span{
            padding-left: 25px;
            padding-right: 0px;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form layui-form-pane" action="/console/role/rewrite/addConfig" lay-filter="layer-from">
                <input type="hidden" name="id">
                <table id="lay-table" lay-filter="lay-table"></table>
                <div class="layui-form-item" hidden>
                    <div class="layui-input-block">
                        <button id="permissionSubmit" class="layui-btn" lay-submit lay-filter="*" >
                            保存
                        </button>
                    </div>
                </div>
            </form
        </div>
    </div>
</div>
<script>
    layui.config({
        base: '${path}/plug-in/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','tables','treeGrid','layers'],function () {
        var tables = layui.tables,
            treeGrid = layui.treeGrid,
            table = layui.table,
            form = layui.form,
            layers = layui.layers,
            $ = layui.$;
        var idList = ${idList!} || [] ;
        form.val("layer-from", $.extend(true,{},parent._data));
        var parmer = {
            url: "/console/menu/rewrite/list",
            where:{sort : ''},
            heightRemove:[".dHead",55],
            toolbar:false,
            cols: [[
                {type:'numbers'},
                {field:"menuName",width:180,title:"菜单名称",templet:function (row) {
                        if(row.children.length > 0){
                            return row.menuName;
                        }else{
                            return row.menuName + '&nbsp;&nbsp; <a  class="layui-btn layui-btn-xs allMotion" menuid="'+ row.id +'" >全选</a >';
                        }
                    }},
                {field:"menuMotion",width:750,title:"动作配置列表" ,templet:function(row){
                        /*拉去动作列表*/
                        $.ajaxSettings.async = false;
                        var motions = [],menuId = row.id;
                        var param = { menuId: menuId , menuId_searchType: "eq",sort:'motion_order',order:'asc'  };
                        $.getJSON("/console/com.fs.common.pojo.MenuMotion/list", param ,function(data){
                            $.each(data.data.rows,function(index,m){
                                var menuMotionId = m.id;//
                                var menuMotionName = m.motionCode +  m.motionName;
                                var motionBox = '';
                                if(idList == '' || idList.indexOf(menuMotionId) == -1){
                                    motionBox = '<input type="checkbox" skin="'+ menuId +'" value="'+ menuMotionId +'" name="'+ menuId +'_'+ index +'"  title="'+menuMotionName+'" lay-skin="primary"/>';
                                }else{
                                    motionBox = '<input type="checkbox" skin="'+ menuId +'" value="'+ menuMotionId +'" name="'+ menuId +'_'+ index +'"  title="'+menuMotionName+'" lay-skin="primary" checked />';
                                }
                                motions.push(motionBox);
                            });
                        });
                        return motions.join("&nbsp;&nbsp;");
                    }},
                ]],
            done: function(res, curr, count){
                $(".allMotion").on("click",function(){
                    var menuid = $(this).attr("menuid");
                    var check = true;
                    $("input[skin="+ menuid +"]").each(function(index,item){
                        if($(item).next().hasClass('layui-form-checked')){
                            check = false;
                        }
                    });
                    $("input[skin="+ menuid +"]").each(function(index,item){
                        if(check){
                            $(item).prop("checked", true);
                            $(item).next().addClass("layui-form-checked");
                        }else{
                            $(item).prop("checked", false);
                            $(item).next().removeClass("layui-form-checked");
                        }
                    })
                });
            }
        };
        var $tables = tables.treeTable(parmer);
    });
</script>
</body>
</html>